/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2006
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
 
package br.ufmg.dees.insane.draw;

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.util.Vector;

/**
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @since	July 2004
 */
public class DiagramDraw extends Draw {
	
	private double factor;
	private double[] x;
	private double[] y;
	
//*****************************************************************************
	
    public DiagramDraw(int n, double[] x, double[] y) {
        this.x = new double[n];
		this.y = new double[n];
		for (int i=0; i<n; i++) {
			this.x[i] = x[i];
			this.y[i] = y[i];
		}
    }
	
//*****************************************************************************
	
    public DiagramDraw() {
    }
	
//*****************************************************************************
	
	public void setFactor(double a) {
		this.factor = a;
	}
	
//*****************************************************************************
	
	public double getFactor() {
		return factor;
	}
	
//*****************************************************************************
	
    public boolean equals(Object obj) {
        return false;
    }
	
//*****************************************************************************
	
    public Vector<Object> getShapes() {
        return null;
    }
	
//*****************************************************************************
	
    /**
     * Draws in a given Graphics.
     *
     * @see   java.awt.Graphics
     */
    public void draw(Graphics2D g2) {
        
		int x1 = this.getLocation().x;
        int y1 = this.getLocation().y;
		double scale = this.getScale();
		
		int n = this.x.length;
		
		GeneralPath gp = new GeneralPath();
		gp.moveTo(x1,y1);
		
		for (int i=0; i<n; i++) {
			
			int x = x1+i;
			float y = y1 + (float)(this.y[i] * scale);
			gp.lineTo(x, y);
			
		}
		
		gp.lineTo(x1+n, y1);
		
		AffineTransform rot = new AffineTransform();
		rot.rotate(this.getAngle()*(-1), getLocation().x, getLocation().y);
		g2.draw(rot.createTransformedShape(gp));
		
    } 
    
//*****************************************************************************
	
    /**
     * Returns the draw bounds in device units.
     *
     * @return the draw bounds
     */
    public Rectangle getBounds() {
        
        int x1 = this.getLocation().x;
        int y1 = this.getLocation().y;
        int x2 = this.getSize().width;
        int y2 = this.getSize().height;
        
        Rectangle rect = new Rectangle(x1, y1, x2 - x1, y2 - y1);
        
        return rect;
    }
    
//*****************************************************************************
}
